﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.DialogUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import Display.aswingui.*;
    import Modules.stats.types.*;
    import L10n.*;

    public class GenericDialog extends Dialog {

        public static const GENERIC:int = 0;
        public static const LEVELUP:int = 1;
        public static const NOBUTTONS:int = 2;
        public static const LOAD_WAIT_TIME:int = 3000;

        protected var m_holder:Sprite;
        protected var m_jpanel:JPanel;
        protected var m_message:String;
        protected var m_title:String;
        protected var m_type:int;
        protected var m_callback:Function;
        protected var m_SkipCallback:Function;
        protected var m_comObject:Object;
        protected var m_icon:String;
        protected var m_iconPos:int;
        protected var m_dialogTitle:String;
        protected var m_loadingDialog:GenericDialog = null;
        protected var m_imagesComplete:Boolean = false;
        protected var activeBgAsset:DisplayObject;
        protected var m_assetBG:DisplayObject;
        protected var m_feedShareViralType:String = "";
        protected var m_customOk:String = "";
        protected var m_relativeIcon:Boolean = true;
        protected var m_assetDependenciesLoaded:int;
        private var m_messageUGC:Boolean;
        protected var m_assetDependencies:Dictionary;

        public function GenericDialog(_arg1:String, _arg2:String="", _arg3:int=0, _arg4:Function=null, _arg5:String="", _arg6:String="", _arg7:Boolean=true, _arg8:int=0, _arg9:String="", _arg10:Function=null, _arg11:String="", _arg12:Boolean=true, _arg13:Boolean=false){
            this.m_assetDependenciesLoaded = 0;
            this.m_assetDependencies = new Dictionary();
            this.m_icon = _arg6;
            this.m_iconPos = _arg8;
            this.m_dialogTitle = _arg5;
            this.m_message = _arg1;
            this.m_title = _arg5;
            this.m_type = _arg3;
            this.m_callback = _arg4;
            this.m_feedShareViralType = _arg9;
            this.m_SkipCallback = _arg10;
            this.m_customOk = _arg11;
            this.m_relativeIcon = _arg12;
            this.m_messageUGC = _arg13;
            this.init();
            super(_arg7);
            this.loadAssets();
        }
        protected function init():void{
            this.m_holder = new Sprite();
            this.addChild(this.m_holder);
            m_jwindow = new JWindow(this.m_holder);
            m_content = this.m_holder;
            m_content.addEventListener(GenericPopupEvent.SELECTED, this.processSelection, false, 0, true);
            m_content.addEventListener(UIEvent.REFRESH_DIALOG, this.onRefreshDialog, false, 0, true);
            m_content.addEventListener("close", this.closeMe, false, 0, true);
        }
        protected function doTrackDialogActions():Boolean{
            if (this.toString() == "[object GenericDialog]"){
                if (this.m_title.length == 0){
                    return (false);
                };
            };
            return (true);
        }
        protected function getAssetDependencies():Array{
            return ([DelayedAssetLoader.GENERIC_DIALOG_ASSETS]);
        }
        protected function loadAssets():void{
            var _local1:String;
            for each (_local1 in this.getAssetDependencies()) {
                Global.delayedAssets.get(_local1, this.makeAssets);
            };
        }
        protected function makeAssets(_arg1:DisplayObject, _arg2:String):void{
            var _local3:int = this.getAssetDependencies().length;
            this.m_assetDependenciesLoaded++;
            this.m_assetDependencies[_arg2] = _arg1;
            if ((((_local3 == 1)) || ((_arg2 == DelayedAssetLoader.GENERIC_DIALOG_ASSETS)))){
                this.m_comObject = _arg1;
            };
            if (this.m_assetDependenciesLoaded >= _local3){
                this.onAssetsLoaded();
            };
        }
        protected function onRefreshDialog(_arg1:UIEvent):void{
            if (m_jwindow){
                ASwingHelper.prepare(m_jwindow);
            };
            this.centerPopup();
        }
        protected function onAssetsLoaded(_arg1:Event=null):void{
            var _local2:Dictionary = this.createAssetDict();
            this.m_jpanel = this.createDialogView(_local2);
            this.finalizeAndShow();
        }
        protected function createAssetDict():Dictionary{
            var _local1:Dictionary = new Dictionary();
            if (this.m_type == GenericDialogView.TYPE_NOBUTTONS){
                _local1["dialog_bg"] = (new this.m_comObject.dialog_bg_notitle_noclose() as DisplayObject);
            } else {
                if (this.m_type == GenericDialogView.TYPE_TITLENOCLOSE){
                    _local1["dialog_bg"] = (new this.m_comObject.dialog_bg_noclose() as DisplayObject);
                } else {
                    if (this.m_title == ""){
                        _local1["dialog_bg"] = (new this.m_comObject.dialog_bg_notitle() as DisplayObject);
                    } else {
                        _local1["dialog_bg"] = (new this.m_comObject.dialog_bg() as DisplayObject);
                    };
                };
            };
            this.m_assetBG = _local1["dialog_bg"];
            return (_local1);
        }
        protected function createDialogView(_arg1:Dictionary):GenericDialogView{
            var _local2:GenericDialogView = new GenericDialogView(_arg1, this.m_message, this.m_dialogTitle, this.m_type, this.m_callback, this.m_icon, this.m_iconPos, this.m_feedShareViralType, this.m_SkipCallback, this.m_customOk, this.m_relativeIcon);
            if (this.m_messageUGC){
                LocaleHelper.localSetting.TextField_adjust(_local2.getMessageTextFiled(), {
                    embedFonts:false,
                    font:EmbeddedArt.SYSTEM_FONT
                });
            };
            return (_local2);
        }
        public function setMessageUGC(_arg1:Boolean):void{
            this.m_messageUGC = _arg1;
        }
        public function hasLoaded():Boolean{
            return (!((this.m_jpanel == null)));
        }
        public function get view():JPanel{
            return (this.m_jpanel);
        }
        protected function processSelection(_arg1:GenericPopupEvent):void{
            var _local2:GenericDialogView = (this.m_jpanel as GenericDialogView);
            var _local3 = "";
            if (_arg1.button == GenericDialogView.YES){
                _local3 = _local2.acceptText;
                if (this.m_callback != null){
                    this.m_callback(_arg1);
                };
            } else {
                if (_arg1.button == GenericDialogView.NO){
                    _local3 = _local2.cancelText;
                    if (this.m_callback != null){
                        this.m_callback(_arg1);
                    };
                } else {
                    if (_arg1.button == GenericDialogView.SKIP){
                        _local3 = _local2.skipText;
                        if (this.m_SkipCallback != null){
                            this.m_SkipCallback(_arg1);
                        };
                    } else {
                        if (_arg1.button == GenericDialogView.SHARE){
                            if (this.m_callback != null){
                                this.m_callback(_arg1);
                            };
                        };
                    };
                };
            };
            if (_local3.length > 0){
                this.countDialogAction(_local3);
            };
            _arg1.stopPropagation();
        }
        protected function closeMe(_arg1:Event):void{
            close();
        }
        public function setupDialogStatsTracking():void{
            this.countDialogAction();
            var _local1:GenericDialogView = (this.m_jpanel as GenericDialogView);
            if (_local1 == null){
                return;
            };
            _local1.setStatsTrackingFunction((this.doTrackDialogActions as Function), this.getDialogStatsTrackingString);
        }
        protected function finalizeAndShow():void{
            ASwingHelper.prepare(this.m_jpanel);
            m_jwindow.setContentPane(this.m_jpanel);
            ASwingHelper.prepare(m_jwindow);
            if (((((this.m_assetBG) && ((this.m_title == "")))) && ((this.m_assetBG.height > m_jwindow.getHeight())))){
                m_jwindow.setPreferredHeight((this.m_assetBG.height + 1));
                ASwingHelper.prepare(m_jwindow);
            };
            var _local1:int = m_jwindow.getWidth();
            var _local2:int = m_jwindow.getHeight();
            m_jwindow.show();
            this.m_holder.width = _local1;
            this.m_holder.height = _local2;
            this.setupDialogStatsTracking();
            onDialogInitialized();
        }
        protected function showLoadingDialog():void{
            TimerUtil.callLater(function ():void{
                if (m_imagesComplete){
                    return;
                };
                m_loadingDialog = new GenericDialog(ZLoc.t("Main", "LoadingDialogText"));
                UI.displayPopup(m_loadingDialog, false, "loadingDialog", true);
            }, LOAD_WAIT_TIME);
        }
        protected function closeLoadingDialog():void{
            this.m_imagesComplete = true;
            if (((this.m_loadingDialog) && (this.m_loadingDialog.isShown))){
                this.m_loadingDialog.close();
            };
        }
        protected function getDialogStatsTrackingString():String{
            var _local1:String = this.m_title;
            if (_local1.length == 0){
                _local1 = this.toString();
            };
            _local1 = GameUtil.trimBadStatsCharacters(_local1);
            return (_local1);
        }
        public function countDialogAction(_arg1:String="view"):void{
            if (!this.doTrackDialogActions()){
                return;
            };
            var _local2:String = this.getDialogStatsTrackingString();
            var _local3:String = GameUtil.trimBadStatsCharacters(_arg1);
            StatsManager.sample(100, StatsKingdomType.DIALOG_STATS, _local2, _local3);
        }

    }
}//package Display.DialogUI 
